package br.ufc.ck0017.semantic.model;

import java.util.HashMap;
import java.util.Map;

public class SemanticProgram {
    private SemanticMainClass semanticMainClass;
    private Map<String, SemanticClass> classes;

    public SemanticProgram() {
        classes = new HashMap<>();
    }

    public void setSemanticMainClass(SemanticMainClass semanticMainClass) throws IllegalArgumentException {
        if (this.semanticMainClass != null) {
            throw new IllegalArgumentException();
        }

        this.semanticMainClass = semanticMainClass;
    }

    public void addClass(String name, SemanticClass newSemanticClass) throws IllegalArgumentException {
        if (classes.containsKey(name)) {
            throw new IllegalArgumentException();
        }

        newSemanticClass.setName(name);
        classes.put(name, newSemanticClass);
    }

    public SemanticMainClass getSemanticMainClass() {
        return semanticMainClass;
    }

    public SemanticClass getClass(String name) {
        return classes.get(name);
    }

    @Override
    public String toString() {
        return "SemanticProgram{" +
                "semanticMainClass=" + semanticMainClass +
                ", classes=" + classes +
                '}';
    }
}
